﻿namespace canlenderwork
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //确定第一天
            string thefirstday = "2022-1-1";
            DateTime Thefirstday = Convert.ToDateTime(thefirstday);
            DateTime theday = Thefirstday;
            //每个月有多少天
            int[] monthday = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            //坐标
            int x = 0; int y = 0; int month = 1;
            //一共四行 每行三个月
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    //设置每个月的初始光标位置
                    x = 30 * j; y = 10 * i;
                    Console.SetCursorPosition(x, y);
                    //打印表头
                    Console.Write(new String(' ', 8));
                    Console.WriteLine(month + "  月");
                    y++;
                    Console.SetCursorPosition(x, y);
                    Console.WriteLine(new String('-', 20));
                    y++;
                    Console.SetCursorPosition(x, y);
                    Console.WriteLine("日 一 二 三 四 五 六");

                    y++;
                    //光标位置
                    Console.SetCursorPosition(x, y);
                    for (int m = 0; m < monthday[3 * i + j]; m++)
                    {
                        //m表示一周的第几天
                        int blank = (int)theday.DayOfWeek;
                        //月份的天数
                        int day = (int)theday.Day;
                        //一月切换光标位置
                        if (day == 1)
                        {
                            Console.SetCursorPosition(x + blank * 3, y);
                        }
                        //周六另起一行
                        if (blank == 6)
                        {
                            if (day < 10)
                                Console.Write(" " + day);
                            else
                                Console.Write(day + " ");
                            y++;
                            Console.SetCursorPosition(x, y);
                        }
                        else
                        {
                            if (day < 10)
                                Console.Write(" " + day + " ");
                            else
                                Console.Write(day + " ");
                        }
                        theday = theday.AddDays(1);
                    }
                    month++;
                }
            }
        }

    }
}